<%@ page language="java" contentType="text/html; charset=UTF-8"	 pageEncoding="UTF-8"%>
<%@ include file="../include/laypublic.jsp" %>
<!DOCTYPE html>
<html>
<head>
  <title>对内建安产值确权</title>
</head>
<script type="text/html" id="layui-row"  >
    <div class="layui-row" id="{0}" >
        <div class="contract-box" >
            <div class="contract-money">
                <table class="layui-table">
                    <colgroup>
                        <col width="90">
                        <col width="200">
                        <col width="200">
                        <col width="200">
                        <col width="200">
                        <col width="200">
                        <col width="200">
                        <col width="200">
						<col width="200">
                    </colgroup>
                    <thead>
                    <tr>
                        <td>子项名称<input type="hidden" value="{1}"  name="subNames"   /></td>
                        <td class=tg-c >{1}</td>                        
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
						<td></td>
						<td></td>
                    </tr>
                    </thead>
                    <tbody>
                    <tr>
                        <th>序号</th>
                        <th>费用类型</th>
						<th>对内合同价(元)(下浮后)</th>
						<th>申报金额(元)(下浮前)</th>
						<th>当月对内确权金额(元)(下浮前)</th>
						<th>其中:不参与下浮金额（元）</th>
						<th>对内下浮率(%)</th>
						<th>当月对内确权金额(元)(下浮后)</th>
						<th>开累对内确权金额(元)(下浮后)</th>
                    </tr>
                    </tbody>
                    <tbody >
                    <tr id="{0}Row-1" level=1 >
                        <td><span class="label" >1</span><input type="hidden" value="1" name="orderIdxs" /><input type="hidden" value="{0}" name="contractSubIds" /></td>
                        <td  class=tg-c  ><b>建安工程费</b><input type="hidden" value="1" name="feeTypes" /><input type="hidden" value="-1" name="feeSmallTypes" /><input type="hidden" value="{1}"  name="itemNameSub"  class="itemNameSub" /><input type="hidden" value="建安工程费" name="typeNames" class="typeNames" /></td>                        
						<td><input type="text" name="inAfterAmounts" readonly style="border:0px" autocomplete="off" class="layui-input incontractfee" /></td>
						<td><input type="text" name="applyPreAmounts" readonly style="border:0px" autocomplete="off" class="layui-input declaredfee" /></td>
						<td><input type="text" name="monthPreAmounts" readonly style="border:0px" autocomplete="off" class="layui-input incaesurefee" /></td>
						<td><input type="text" name="notDownAmounts" readonly style="border:0px;" autocomplete="off" class="layui-input notdownfee" /></td>
						<td><input type="text" name="inDownRates" readonly style="border:0px" autocomplete="off" class="layui-input indiscount" /></td>
						<td><input type="text" name="monthAfterAmounts" readonly style="border:0px" autocomplete="off" class="layui-input incaesurefeeafter" /></td>
						<td><input type="text" name="addupAfterAmounts" readonly style="border:0px" autocomplete="off" class="layui-input klincaesurefeeafter" />
						<input type="hidden"   class="histroycaesurefeeafter" /></td>
                    </tr>
                    <tr id="sub{0}Row-1.1"  level=2 >
                        <td><span class="label" >1.1</span><input type="hidden" value="1.1" name="orderIdxs" /><input type="hidden" value="{0}" name="contractSubIds" /></td>
                        <td  class=tg-c  ><label>土建</label><input type="hidden" value="1" name="feeTypes" /><input type="hidden" value="{1}" name="itemNameSub"  class="itemNameSub" /><input type="hidden" value="1.1" name="feeSmallTypes" /><input type="hidden" value="土建" name="typeNames"  class="typeNames"  /></td>
						<td><input type="text" name="inAfterAmounts" readonly lay-verify="required|floatNumber" style="border:0px" autocomplete="off" class="layui-input  incontractfee" /></td>
						<td><input type="text" name="applyPreAmounts" lay-verify="required|floatNumber"  autocomplete="off" class="layui-input decimal declaredfee" /></td>
						<td><input type="text" name="monthPreAmounts" lay-verify="required|floatNumber"  autocomplete="off" class="layui-input decimal incaesurefee" /></td>
						<td><input type="text" name="notDownAmounts" lay-verify="required|floatNumber" autocomplete="off" class="layui-input decimal notdownfee" /></td>
						<td><input type="text" name="inDownRates" readonly lay-verify="required|floatNumber" style="border:0px" autocomplete="off" class="layui-input indiscount" /></td>
						<td><input type="text" name="monthAfterAmounts" readonly lay-verify="required|floatNumber" style="border:0px" autocomplete="off" class="layui-input incaesurefeeafter" /></td>
						<td><input type="text" name="addupAfterAmounts" readonly lay-verify="required|floatNumber" style="border:0px" autocomplete="off" class="layui-input klincaesurefeeafter" />
						<input type="hidden"   class="histroycaesurefeeafter" /></td>                  		
					</tr>
                    <tr id="sub{0}Row-1.2"  level=2 >
                        <td><span class="label">1.2</span> <input type="hidden" value="1.2" name="orderIdxs" /><input type="hidden" value="{0}" name="contractSubIds" /></td>
                        <td  class=tg-c  ><label>安装</label><input type="hidden" value="1" name="feeTypes" /><input type="hidden" value="{1}" name="itemNameSub" class="itemNameSub" /><input type="hidden" value="1.2" name="feeSmallTypes" /><input type="hidden" value="安装" name="typeNames"  class="typeNames" /></td>
						<td><input type="text" name="inAfterAmounts" readonly lay-verify="required|floatNumber" style="border:0px" autocomplete="off" class="layui-input  incontractfee" /></td>
						<td><input type="text" name="applyPreAmounts" lay-verify="required|floatNumber"  autocomplete="off" class="layui-input decimal declaredfee" /></td>
						<td><input type="text" name="monthPreAmounts" lay-verify="required|floatNumber"  autocomplete="off" class="layui-input decimal incaesurefee" /></td>
						<td><input type="text" name="notDownAmounts" lay-verify="required|floatNumber" autocomplete="off" class="layui-input decimal notdownfee" /></td>
						<td><input type="text" name="inDownRates" readonly lay-verify="required|floatNumber" style="border:0px" autocomplete="off" class="layui-input indiscount" /></td>
						<td><input type="text" name="monthAfterAmounts" readonly lay-verify="required|floatNumber" style="border:0px" autocomplete="off" class="layui-input incaesurefeeafter" /></td>
						<td><input type="text" name="addupAfterAmounts" readonly lay-verify="required|floatNumber" style="border:0px" autocomplete="off" class="layui-input klincaesurefeeafter" />
						<input type="hidden"   class="histroycaesurefeeafter" /></td>  
					</tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</script>

<script type="text/html" id="layui-row-tr" >
<tr id="{0}" level={1} >
 <td><span class="label" >{2}</span><input type="hidden" value="{2}" name="orderIdxs" /><input type="hidden" value="{3}" name="contractSubIds" /></td>
 <td><input type="text" maxlength="50" lay-verify="required" value="{4}" autocomplete="off" class="layui-input typeNames" name="typeNames" />
  <input type="hidden" value="{5}" name="feeTypes" class="feeTypes" />
  <input type="hidden" value="{6}" name="feeSmallTypes" class="feeSmallTypes" />
  <input type="hidden" value="{7}" name="itemNameSub" class="itemNameSub" />
 </td>
 <td><input type="text" value="{8}" name="inAfterAmounts" readonly lay-verify="required|floatNumber" autocomplete="off" style="border:0px" class="layui-input incontractfee" /></td>
 <td><input type="text" name="applyPreAmounts" lay-verify="required|floatNumber" maxlength="10" autocomplete="off" class="layui-input decimal declaredfee" /></td>
 <td><input type="text" name="monthPreAmounts" lay-verify="required|floatNumber" maxlength="10" autocomplete="off" class="layui-input decimal incaesurefee" /></td>
 <td><input type="text" name="notDownAmounts" lay-verify="required|floatNumber"  autocomplete="off" class="layui-input decimal notdownfee" /></td>
 <td><input type="text" value="{9}" name="inDownRates" readonly lay-verify="required|floatNumber" style="border:0px" autocomplete="off" class="layui-input indiscount" /></td>
 <td><input type="text" name="monthAfterAmounts" readonly lay-verify="required|floatNumber" style="border:0px" autocomplete="off" class="layui-input incaesurefeeafter" /></td>
 <td><input type="text" name="addupAfterAmounts" readonly lay-verify="required|floatNumber" style="border:0px" autocomplete="off" class="layui-input klincaesurefeeafter" />
 <input type="hidden" value="{10}"  class="histroycaesurefeeafter" /></td>
</tr>
</script>

<script type="text/html" id="list-mode-tr" >
<tr id="LISTMODERow-{0}" >
<td><span class="label" >{0}</span><input type="hidden" value="{0}" name="showIdxLists" /></td> 
<td><input type="text" value="{1}" name="subNameLists" readonly style="border:0px" lay-verify="required" autocomplete="off" class="layui-input  name" /></td>
<td><input type="text" value="{2}" name="subUnitLists" readonly style="border:0px" lay-verify="required" autocomplete="off" class="layui-input integer unit" /></td>
<td><input type="text" value="{3}" name="cotUnitPriceLists" readonly style="border:0px" lay-verify="required|floatNumber" autocomplete="off" class="layui-input decimal contractprice" /></td> 
<td><input type="text" value="{4}" name="cotSumPriceLists" readonly style="border:0px" lay-verify="required|floatNumber" autocomplete="off" class="layui-input decimal contractamount" /></td> 
<td><input type="text" value="" name="applyNumLists" maxlength="10" lay-verify="required|floatNumber" autocomplete="off" class="layui-input decimal declarednum" /></td> 
<td><input type="text" value="" name="applyAmountLists" readonly lay-verify="required|floatNumber" style="border:0px" autocomplete="off" class="layui-input decimal declaredamount" /></td> 
<td><input type="text" value="" name="sureNumLists" maxlength="10" lay-verify="required|floatNumber" autocomplete="off" class="layui-input decimal incaesurenum" /></td> 	
<td><input type="text" value="" name="monthSureAmountLists" readonly lay-verify="required|floatNumber" style="border:0px" autocomplete="off" class="layui-input decimal samemonthincaesureamount" /></td> 	
<td><input type="text" value="" name="addupSureAmounts" readonly lay-verify="required|floatNumber" style="border:0px" autocomplete="off" class="layui-input decimal kaileiincaesureamount" />
<input type="hidden"  value="{5}" name="hisotryprice" class="hisotryprice"  />
<input type="hidden"  value="0" name="cotNumLists" />
</td> 	
</tr>
</script>
<style>
.contract-price-info{
 	display:none;
}
.contract-price-info legend{
	text-align:left;
	cursor: default;
	width:175px;
}

.list-title{
	display:block;
	width:342px;
	text-align:right;
	left:55px;
	font-size:.89em;
}

.pos-r{
	position: relative;
}
.pos-a{
	position: absolute;
}

.margin-bot10 {
	margin-bottom: 10px;
}

.margin-lt10 {
	margin-left: 10px;
}

.layui-row+.layui-row {
	margin-top: 10px;
}

.tg-l {
	text-align: left;
}

.tg-c {
	text-align: center;
}

.tg-r {
	text-align: right;
}

.contract-list {
	margin-top: 20px;
}

.contract-box {
	width: 100%;
	min-height: 100px;
}

.contract-money {
	width: 94%;
	margin: 0px auto;
}

.contract-money .layui-table {
	margin: 0;
}

.contract-money th {
	text-align: center;
	height: 38px;
}

.contract-money .label {
	display: block;
	width: 45px !important;
	margin-left: 15px;
}

.fieldset {
	margin-top: 5px;
	margin-bottom: 0px
}

.layui-legend {
	background-color: #5fb878;
	font-size: 15px !important;
	width: 140px;
}

.layui-form-item {
	margin-bottom: 5px;
	clear: both;
	*zoom: 1;
}

.layui-form-label {
	width: 160px;
}

.right {
	float: right;
}

.width106 {
	width: 106px;
}

.bankRow+.bankRow {
	border-top: 1px solid #e0e0e0;
	margin-top: 20px;
	padding-top: 20px;
}
</style>
<body>
	<div class="layui-fluid">
		<div class="layui-card">
			<div style="padding-top: 15px;">&nbsp;</div>
			<form class="layui-form" id="addInfo_form" lay-filter="addInfo_form">
				<div class="layui-tab layui-tab-brief" >
					<div class="layui-tab-content">
						<div class="layui-tab-item layui-show">
							
							<fieldset class="layui-elem-field layui-field-title fieldset" id="baseInfo" >
								<legend class="layui-btn layui-legend"
									style="text-align: left; cursor: default;" >项目基础信息 ></legend>
								<div class="layui-form-item">
									<div class="layui-inline">
										<label class="layui-form-label">申请公司</label>
										<div class="layui-input-inline">
											<input type="hidden" name="hrOrgid" value="${bindOrgId}">
											<input type="text" value="${bindOrgName}"
												style="border: 0px;" readonly="readonly" class="layui-input">
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label">申请部门</label>
										<div class="layui-input-inline">
											<input type="hidden" name="hrDeptid" value="${bindDeptId}">
											<input type="text" value="${bindDeptName}"
												style="border: 0px;" readonly="readonly" class="layui-input">
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label" >申请人</label>
										<div class="layui-input-inline" >
											<input type="hidden" name="hrStaffApplyid"
												value="${SESSION_KEY_USER_DETAIL.hrStaffId }"> <input type="text" name="staffname" value="${staffName }" readonly="readonly" style="border: 0px" autocomplete="off"
												class="layui-input" >
										</div>
									</div>
								</div>
								<div class="layui-form-item"  >	
									<div class="layui-inline" >
										<label class="layui-form-label" >合同类型</label>
										<div class="layui-input-inline" >										
											<select id="add_select_cotType" lay-filter="add_select_cotType" 
												name="cotType" lay-verify="required" >
												<option value="" >请选择</option>
												<option value="1" >内部协议</option>
												<option value="2" >分包合同</option>
											</select>									
										</div>
									</div>						
									<div class="layui-inline" >
										<label class="layui-form-label">合同名称</label>
										<div class="layui-input-inline">
											<input type="hidden" id="cotNameId" name="refContractName">
											<select id="add_select_proId" name="proCodeAndCodes" lay-filter="add_select_proId" lay-verify="required" lay-search>
				      						</select>
										</div>
									</div>	
									<div class="layui-inline" >
										<label class="layui-form-label" >合同单位名称</label>
										<div class="layui-input-inline" >
											<input type="hidden" id="sgCoopId" name="sgCoopId" value="">
											<input type="text" id="id_contractUnitName"
												style="border: 0px;" readonly="readonly" lay-verify="required"
												class="layui-input">																						
										</div>
									</div>									
								</div>
								<div class="layui-form-item"  >										
									<div class="layui-inline">
										<label class="layui-form-label" >项目名称</label>
										<div class="layui-input-inline" >
											<input type="text" id="id_proName" name="proName" value="" style="border: 0px;width:220px"
												readonly="readonly" class="layui-input">
										</div>
									</div>									
									<div class="layui-inline">
										<label class="layui-form-label">项目编号</label>
										<div class="layui-input-inline">
											<input type="text" id="id_proCode" name="proCode" value="" style="border: 0px;"
												readonly="readonly" class="layui-input">
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label">区域公司</label>
										<div class="layui-input-inline">
											<input type="hidden" id="areaId" name="hrOrgAreaId" value="">
											<input type="text" id="id_regionalCompany"
												value="" readonly="readonly"
												style="border: 0px;width:220px" autocomplete="off" class="layui-input">
										</div>
									</div>								
								</div>
								<div class="layui-form-item"  >									
									<div class="layui-inline" >
										<label class="layui-form-label" >项目公司</label>
										<div class="layui-input-inline" >
											<input type="hidden" id="compId" name="hrOrgProId"  value="">
											<input type="text" id="id_projectCompany" value=""
												style="border: 0px;width:220px" readonly="readonly" class="layui-input">
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label" >实施机构</label>
										<div class="layui-input-inline" >
											<input type="text" id="id_ImplementingBody" name="carryOrg" style="border: 0px;width:220px"
												readonly="readonly" class="layui-input">
										</div>
									</div>
									<div class="layui-inline" >
										<label class="layui-form-label" >项目地址</label>
										<div class="layui-input-inline" >
											<input type="hidden" id="sgCityId" name="sgCityId" value="">
											<input type="text" id="id_projectAddress" name="projectAddress" value=""
												style="border: 0px;" readonly="readonly" class="layui-input">
										</div>
									</div>
								</div>
								<div class="layui-form-item"  >
									<div class="layui-inline" >
										<label class="layui-form-label" >项目负责人</label>
										<div class="layui-input-inline" >
											<input type="text" id="id_projectLeader" name="proLeader"
												 readonly="readonly" style="border: 0px;" class="layui-input">
										</div>
									</div>
									<div class="layui-inline" >
										<label class="layui-form-label" >确权模式</label>
										<div class="layui-input-inline" >
											<input type="hidden" name=sureType id="id_sureType" value="">
											<input type="text" id="rightconfirmationmode" value="" style="border:0px;" readonly="readonly" class="layui-input" />										
										</div>
									</div>
									<div class="layui-inline" >
										<label class="layui-form-label" >确权月份</label>
										<div class="layui-input-inline" >
											<input type="text" class="layui-input" id="caesureMonth" name="sureMonthStr" lay-verify="required" readonly>									
										</div>
									</div>									
								</div>
								<div class="layui-form-item"  >
									<div class="layui-inline" >
										<label class="layui-form-label" >当月对外确权金额（下浮后）（元）</label>
										<div class="layui-input-inline" >
											<input type="text" readonly style="border:0px" name="monthOutAmount"  id="id_monthOutAmount" value="" lay-verify="required|floatNumber" class="layui-input" >
										</div>
									</div>
									<div class="layui-inline" >
										<label class="layui-form-label" >开累对外确权金额（下浮后）（元）</label>
										<div class="layui-input-inline" >
											<input type="text" readonly style="border:0px" name="addupOutAmount"  id="id_addupOutAmount" value="" lay-verify="required|floatNumber" class="layui-input" >											
										</div>
									</div>
									<div class="layui-inline" >
										<label class="layui-form-label" >当月对内确权金额（下浮后）（元）</label>
										<div class="layui-input-inline">
											<input type="text" readonly style="border:0px" name="monthAfterAmountTotal"  id="id_monthAfterAmount" value="0" lay-verify="required|floatNumber" class="layui-input" >
										</div>
									</div>
								</div>
								<div class="layui-form-item">
									<div class="layui-inline" >
										<label class="layui-form-label" >开累对内确权金额（下浮后）（元）</label>
										<div class="layui-input-inline" >
											<input type="text" readonly style="border:0px" name="addupAfterAmountTotal"  id="id_addupAfterAmount" value="0" lay-verify="required|floatNumber" class="layui-input" >											
										</div>
									</div>
								</div>				
							</fieldset>						
							<fieldset class="layui-elem-field layui-field-title fieldset contract-price-info"  >													
								<legend class="layui-btn layui-legend" >确权明细-下浮模式  ></legend>
								<div class="contract-list" >																	
									<div class="contract-box margin-bot10" >
	            						<div class="contract-money">
	                						<table class="layui-table">
							                    <colgroup>
							                        <col width="100"  >
							                        <col width="260"  >
							                        <col width="290" >
							                        <col width="290" >
							                        <col width="290" >
							                        <col width="290" >
							                        <col width="290" >
							                    </colgroup>
												<thead>
													<tr>
														<th></th>
											            <th>对内合同价(元)(下浮后)</th>
											  			<th>申报金额(元)(下浮前)</th>
														<th>当月对内确权金额(元)(下浮前)</th>
														<th>对内下浮率(%)</th>
														<th>当月对内确权金额(元)(下浮后)</th>
														<th>开累对内确权金额(元)(下浮后)</th>
													</tr>
												</thead>
												<tbody >
													<tr>
													    <td class="tg-r" >合计</td>
														<td><input type="text" value="0" id="incontractfee" style="border:0px" lay-verify="required|floatNumber" name="inAfterAmount" readonly autocomplete="off" class="layui-input " /></td>
														<td><input type="text" value="0" id="declaredfee" style="border:0px" lay-verify="required|floatNumber" name="applyPreAmount" readonly autocomplete="off" class="layui-input " /></td>
														<td><input type="text" value="0" id="incaesurefee" style="border:0px" lay-verify="required|floatNumber" name="monthPreAmount" readonly autocomplete="off" class="layui-input " />
															<input type="hidden" value="0" id="notdownfee" style="border:0px;" lay-verify="required|floatNumber" name="notDownAmount" readonly autocomplete="off" class="layui-input " />
														</td>
														<td><input type="text" value="0" id="indiscount" style="border:0px" lay-verify="required|floatNumber" name="inDownRate" readonly autocomplete="off" class="layui-input " /></td>
														<td><input type="text" value="0" id="incaesurefeeafter" style="border:0px" lay-verify="required|floatNumber" name="monthAfterAmount" readonly autocomplete="off" class="layui-input" /></td>
														<td><input type="text" value="0" id="klincaesurefeeafter" style="border:0px" lay-verify="required|floatNumber" name="addupAfterAmount" readonly autocomplete="off" class="layui-input" /></td>													
													</tr>
								                </tbody>
							                </table>
	                    				</div>
                    				</div> 							
								</div>
							</fieldset>				
							<fieldset class="layui-elem-field layui-field-title fieldset contract-price-info"   >			    	
							    	<legend class="layui-btn layui-legend" >确权明细-清单模式  ></legend>
							    	<div style="height:20px;">&nbsp;</div>																
									<div class="contract-box margin-bot10" >
	            						<div class="contract-money" >
	            						    <table class="layui-table" >
							                    <colgroup>
							                        <col width="100" >
							                        <col width="290" >
							                        <col width="290" >
							                        <col width="290" >
							                        <col width="290" >
							                        <col width="290" >
							                        <col width="290" >
							                    </colgroup>
												<thead>
													<tr>
														<th></th>
														<th>合同金额（元）</th>
														<th>申报数量</th>
														<th>申报金额（元）</th>
														<th>对内确权数量</th>
														<th>当月对内确权金额（元）</th>
														<th>开累对内确权金额（元）</th>
													</tr>
												</thead>
												<tbody >
													<tr>
													    <td class="tg-r" >合计</td>
														<td><input type="text" value="0" id="contractamount" style="border:0px" lay-verify="required|floatNumber" name="cotSumPrice" readonly autocomplete="off" class="layui-input " /></td>
														<td><input type="text" value="0" id="declarednum" style="border:0px" lay-verify="required|floatNumber" name="applyNums" readonly autocomplete="off" class="layui-input " /></td>
														<td><input type="text" value="0" id="declaredamount" style="border:0px" lay-verify="required|floatNumber" name="applyAmount" readonly autocomplete="off" class="layui-input " /></td>
														<td><input type="text" value="0" id="incaesurenum" style="border:0px" lay-verify="required|floatNumber" name="sureNums" readonly autocomplete="off" class="layui-input " /></td>
														<td><input type="text" value="0" id="samemonthincaesureamount" style="border:0px" lay-verify="required|floatNumber" name="monthAfterAmount" readonly autocomplete="off" class="layui-input" /></td>
														<td><input type="text" value="0" id="kaileiincaesureamount" style="border:0px" lay-verify="required|floatNumber" name="addupAfterAmount" readonly autocomplete="off" class="layui-input" /></td>													
													</tr>
								                </tbody>
							                </table>	                						
	                    				</div>
                    				</div>																								
									<div class="contract-box " id="list-mode" >
	            						<div class="contract-money"		>
	                						<table class="layui-table"	>
							                    <colgroup>
							                        <col width="90"     >
							                        <col width="600"    >
							                        <col width="300"    >
							                        <col width="300"    >
							                        <col width="300"    >							                        
							                        <col width="300"    >
							                        <col width="300"    >
							                        <col width="300"    >
							                        <col width="300"    >
							                        <col width="300"    >
							                    </colgroup>
												<thead>
													<tr>
														<th>序号</th>
														<th>分部分项清单名称</th>
														<th>计量单位</th>
														<th>合同单价(元)</th>
														<th>合同金额（元）</th>
														<th>申报数量</th>
														<th>申报金额（元）</th>
														<th>对内确权数量</th>
														<th>当月对内确权金额（元）</th>														
														<th>开累对内确权金额（元）</th>
													</tr>
												</thead>
												<tbody>																																				
								                </tbody>
							                </table>
	                    				</div>
	                    			</div>                                       		                    										
							</fieldset>										
			
							<fieldset class="layui-elem-field layui-field-title fieldset" id="baseInfo" >
								<legend class="layui-btn layui-legend" style="text-align: left; cursor: default;" >附件 ></legend>
								<div style="margin-top: 20px;" >
									<div class="layui-form-item" >
										<label class="layui-form-label" style="width: 350px;">支持pdf、excel、word、图片资料，可上传多个</label>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label" >计算稿（选填）</label>
										<div class="layui-input-block">
											<div class="layui-upload">
												<button type="button" class="layui-btn" id="1-upload-more">上传</button>
												<div class="layui-upload-list" id="1-upload-more-list" ></div>
											</div>
										</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label" >签字扫描件（选填）</label>
										<div class="layui-input-block">
											<div class="layui-upload">
												<button type="button" class="layui-btn" id="2-upload-more">上传</button>
												<div class="layui-upload-list" id="2-upload-more-list" ></div>
											</div>
										</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label" >其他附件（选填）</label>
										<div class="layui-input-block">
											<div class="layui-upload">
												<button type="button" class="layui-btn" id="3-upload-more">上传</button>
												<div class="layui-upload-list" id="3-upload-more-list" ></div>
											</div>
										</div>
									</div>
								</div>
							</fieldset>
						</div>
					</div>
				</div>
				<div class="layui-form-item"
					style="position: fixed ! important; right: 30px; bottom: 45%; z-index: 10000;">
					<div class="layui-input-block">
						<button
							class="layui-btn layui-bg-blue layui-btn-normal layui-btn-lg  layui-btn-radius"
							type="button" lay-submit lay-filter="addInfo_form_submit"
							id="addInfo_form_submit">
							<i class="layui-icon layui-icon-ok layuiadmin-button-btn"></i> 提交
						</button>
					</div>
				</div>
			</form>
		</div>
	</div>
</body>
</html>
<script type="text/javascript"  >
String.prototype.format = function () {
	var model = arguments;
    return this.replace(/\{(\d+)\}/g, function (s, i) { 
    	/* return !!model[i]?model[i]:''; */
        return model[i];
    });
}
String.prototype.toInt = function () {
	if(this==''){
		return 0;
	}
	return parseInt(this);
}
String.prototype.toFloat = function () {
	if(this==''){
		return 0;
	}
	return parseFloat(this);
}
Number.prototype.toMoney = function () {
	var m = Math.pow(10, 2);
	return Math.round(this * m) / m;
}
var getPercentage = function(a, b, d) {
	var quotient = Number(b) != 0 ? a / b : 0;
	if (d == true) {
		return setDecimalPlaces((1 - quotient) * 100, 2);
	}
	return setDecimalPlaces(quotient * 100, 2);
}

var setDecimalPlaces = function(f, digit) {
	var m = Math.pow(10, digit);
	return Math.round(f * m) / m;
}
function parentGroup($, type, id) {
	if(type=="incontractfee"){
		amountParentGroup($, 'incontractfee', id);
		countTopRows($, ['incontractfee']);				
	}
	if(type=="declaredfee"){
		amountParentGroup($, 'declaredfee', id);
		countTopRows($, ['declaredfee']);				
	}
	if(type=="incaesurefee" ||type=="notdownfee"){
		if(type=="incaesurefee"){
			amountParentGroup($, 'incaesurefee', id);
		}else if(type=="notdownfee"){
			amountParentGroup($, 'notdownfee', id);
		}	
		countTopRows($, ['incaesurefee','notdownfee','incaesurefeeafter','klincaesurefeeafter']);
		var incaesurefee = $('#incaesurefee').val();
		var indiscount = $('#indiscount').val();
		var notdownfee =  $('#notdownfee').val();		
		var incaesurefeeafter = notdownfee.toFloat() + (incaesurefee -notdownfee)* (1-indiscount/100);
		//重新计算总当月对内确权金额
		//$('#incaesurefeeafter').val(incaesurefeeafter.toFixed(2));
		//重新计算总开累对内确权金额
		var arr = id.split('.');
		var trId = arr[0].replace('sub', '');
		var $tr = $('[id="' + trId + '"]');
		var klincaesurefeeafter = $("tr[level=1]").find('.histroycaesurefeeafter').inputTotal();
		var newklincaesurefeeafter = incaesurefeeafter + klincaesurefeeafter;
		//$('#klincaesurefeeafter').val(newklincaesurefeeafter.toFixed(2));
		//$('#id_monthAfterAmount').val(incaesurefeeafter.toFixed(2));
		//$('#id_addupAfterAmount').val(newklincaesurefeeafter.toFixed(2));
	}
}
function amountParentGroup($, type, id) {
	var arr = id.split('.');
	if (arr.length == 3) {
		var item = arr.slice(0, 2);
		var trId = item.join('.');				
		var $tr = $('[id="' + trId + '"]');
		$tr.find('.' + type).val($("tr[id^='" + trId + ".'][level=3]").find('.' + type).inputTotal());
		var $childTr  = $("tr[id^='" + trId + ".'][level=3]");
		incaesurefee2(type,$tr,$childTr);
		if(type=="incaesurefee" || type=='notdownfee'){
			var $parentTr = $('[id="' + item[0].replace('sub', '') + '"]');
			$parentTr.find('.' + type).val($("tr[id^='" + item[0] + ".'][level=2]").find('.' + type).inputTotal());
			var $pTr = $("tr[id^='" + item[0] + ".'][level=2]")
			incaesurefee3(type,$parentTr,$pTr);
		}
	}
	if (arr.length >= 2) {
		var trId = arr[0].replace('sub', '');				
		var $tr = $('[id="' + trId + '"]');
		$tr.find('.' + type).val($("tr[id^='" + arr[0] + ".'][level=2]").find('.' + type).inputTotal());
		if(type=="incaesurefee" || type=='notdownfee'){
			var $parentTr = $('[id="' + arr[0].replace('sub', '') + '"]');
			$parentTr.find('.' + type).val($("tr[id^='" + arr[0] + ".'][level=2]").find('.' + type).inputTotal());
			var $pTr = $("tr[id^='" + arr[0] + ".'][level=2]")
			incaesurefee3(type,$parentTr,$pTr);
		}
	}
}
function countTopRows($, types) {
	var $contractListLayuiRow = $('.layui-row');
	types.forEach(function(e) {		
		var $total = $('#' + e);
		var total = $contractListLayuiRow.find("tr[id$='Row-1'] input[type=text]." + e).inputTotal();
		$total.val(total);		
		if(e=='incaesurefeeafter'){
			$('#id_monthAfterAmount').val(total);
		}
		if(e=='klincaesurefeeafter'){
			$('#id_addupAfterAmount').val(total);
		}
	});
}
function eightS4() {
    function S4() {
        return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
    }
    return (S4()+S4()+""+S4()+""+S4()+""+S4()+""+S4()+S4()+S4()).toLocaleUpperCase();
}
function setReadonly($t) {
	if ($t) {
		$t.find('input[type=text].incontractfee').prop('readonly', true).removeAttr('lay-verify');
		$t.find('input[type=text].notdownfee').prop('readonly', true).removeAttr('lay-verify');
		$t.find('input[type=text].declaredfee').prop('readonly', true).removeAttr('lay-verify');
		$t.find('input[type=text].incaesurefee').prop('readonly', true).removeAttr('lay-verify');
	}
}
    var listModeData = [{name:'',unit:'元',contractprice:0,contractamount:0,historyprice:0 }];
	var subList = [];
	var proName;
	var proNameid;
	//静态资源路径前缀
	var staticPath = '${fileHttpPre}';
	var stateJSON = <infopub:dicJson groupNo="A00010028" />;
	layui.config({base : '${ctx}/resources/layuiadmin/' //静态资源所在路径
			})
			.extend({
				index : 'lib/index' //主入口模块
			})
			.use([ 'index', 'set', 'upload', 'element', 'laydate' ], function() {
						var $ = layui.$, form = layui.form, element = layui.element, laydate = layui.laydate, upload = layui.upload;
						// 正则校验
						form.verify({
							//验证汉字
						    CHS:[
						    	/^[\u0391-\uFFE5]+$/
						    	,'只能输入汉字'
						  	],
						  	//名字校验
						  	COC: [
								/^[\u4e00-\u9fa5_a-zA-Z0-9]+$/
								,'请输入正确的名称'
						  	],
						  	//大于0的正整数
						  	intNumber:[
								/^[1-9]\d*$/
								,'请输入正确的数字'
						  	],
						  	//数字只能有两位小数
						  	floatNumber:[
								/^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
								,'请输入正确的数字'
						  	],
						  	telNumber:[/^[1][3,4,5,7,8,9][0-9]{9}$/
								  		,'请输入正确的号码'
							],
						  	//数字大于0，并只能有两位小数
						  	floatAmount:[
								/^([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
								//var pattern=/^((\d+\.\d*[1-9]\d{1})|(\d*[1-9]\d*\.\d{2}))$/; 
								,'请输入正确的数字'
						  	]
						});
						
						uploadRender(1, upload, $);
						uploadRender(2, upload, $);
						uploadRender(3, upload, $);
						
						laydate.render({ 
							elem: '#caesureMonth'
						    ,type: 'month'
						    ,trigger:'click'
						    ,done: function(value, date){
						    	var incaeSureMonth = value;
						    	var proId = $('#add_select_proId').val();
						  	     $.ajax({
						 			type : "POST", //提交方式  
						 			url : "${ctx}/incaeSure/getMonthAfterAmount",//路径  
						 			data : {
						 				"proCodeAndCodes" : proId,
						 				"sureMonth" : incaeSureMonth
						 			},//数据，这里使用的是Json格式进行传输  
						 			success : function(result) {//返回数据根据结果进行相应的处理 
						 				if (result.flag == true) {
						 					//当月对外确权金额(下浮后)元
											if(result.outcaeSure!=null&&result.outcaeSure!=''){
												$("#id_monthOutAmount").val(result.outcaeSure);						
											}else{
												$("#id_monthOutAmount").val(0);
											}
											//所有月份合计(对外确权金额(下浮后)元)开累对外确权金额（下浮后）
											if(result.monthAfterAmount!=null&&result.monthAfterAmount!=''){
												$("#id_addupOutAmount").val(result.monthAfterAmount);
											}else{
												$("#id_addupOutAmount").val(0);
											}
						 					form.render();
						 				}
						 			}
						 		});	
					  	     
					  	    }
						});
						
						(function($) {
							$.fn.inputTotal = function() {
								var sum = 0;
								this.each(function() {
									var thisNum = $(this);
									var val = !!thisNum.val() ? thisNum.val()
											: 0;
									var num = parseFloat(val);
									sum = setDecimalPlaces(sum + num, 2);
								});
								return sum;
							};
						})($);	
												
						form.on('select(add_select_cotType)', function(data) {
							var types = data.value;
							if(types==''||types==null){
								$('select[id="add_select_proId"]').html('');
								$('#caesureMonth').val('');
								$("#id_monthOutAmount").val('');
								$("#id_addupOutAmount").val('');
					    		form.render();
								layer.msg('请选择合同类型',{icon: 3});
								return;
							}else{
								$('select[id="add_select_proId"]').html('');
								$('#caesureMonth').val('');
								$("#id_monthOutAmount").val('');
								$("#id_addupOutAmount").val('');
					    		form.render();
					    		getIncaeSureByTypes(types);
							}	
						});
						
						form.on('select(add_select_proId)', function(data) {
							var id = data.value;
							proNameid = data.value;
							proName = data.elem.getAttribute('proName');
							if(id==''||id==null){
								layer.msg('请选择合同名称',{icon: 1});
								$('#caesureMonth').val('');
								$("#id_monthOutAmount").val('');
								$("#id_addupOutAmount").val('');
					    		return;
							}else{
								getIncaeSureByProCode(id);
								$('#caesureMonth').val('');
								$("#id_monthOutAmount").val('');
								$("#id_addupOutAmount").val('');
								$("#declaredfee").val(0);
								$("#incaesurefee").val(0);
								$("#notdownfee").val(0);
								$("#incaesurefeeafter").val(0);
								$("#klincaesurefeeafter").val(0);
							}														
						});
											
						form.on('submit(addInfo_form_submit)', function(data) {
							$("#addInfo_form_submit").removeAttr("lay-submit").removeClass("layui-bg-blue").addClass("layui-btn-disabled");
							//提交 Ajax 成功后，静态更新表格中的数据
		                   	
		                   	$.ajax({
		                       	type : 'post',
		            			url : basePath + '/incaeSure/save',
		                       	data: $('#addInfo_form').serialize(),
		            			success:function(result){
		            				if(result.success){
		            					layer.closeAll('loading'); //关闭loading
		            					layer.msg('提交单据成功~',{icon: 1});
		            					//两秒后关闭当前页面
		            					setTimeout(function(){
		            						/**
		            						 * 查找父菜单，并刷新
		            						 */
		            						var topDoc = $(window.top.document);
		            						var path = basePath + '/incaeSure/list';
		            						// 获取页面名称
		            						var name = topDoc.find(".layui-nav-item [lay-href^='" + path + "']").text();
		            						if(name == '' || name == null){
		            							name = '对内建安产值确权';
		            						}
		            						window.parent.layui.index.openTabsPage(path, name);
		            						var iframe = window.parent.layui.admin.tabsBody(window.parent.layui.admin.tabsPage.index).find(".layadmin-iframe");
		            						iframe[0].contentWindow.location.reload(true);
		            						
		            						/**
		            						 * 关闭当前页
		            						 */
		            						var currPath = basePath + '/incaeSure/add';
		            						var layid = topDoc.find("li[lay-id^='" + currPath + "']").attr('lay-id');
		            						window.parent.layui.element.tabDelete('layadmin-layout-tabs', layid);//关闭当前页
		            				        }, 2000);
		            				}else{
		            					layer.closeAll('loading'); //关闭loading
		              					$("#addInfo_form_submit").removeClass("layui-btn-disabled").addClass("layui-bg-blue").attr("lay-submit","");
		            					layer.msg(result.msg,{icon: 7});
		            			  	}
		            			}
		                   	});
						});
						
					});
	
	var incaesurefee = function(type,$tr){
		if(type=='incaesurefee' ||type=='indiscount' || type=='notdownfee'){
			var incaesurefee = $tr.find(".incaesurefee").val().toFloat();
			var notdownfee = $tr.find(".notdownfee").val().toFloat();
			var $indiscount = $tr.find(".indiscount"),indiscount = $indiscount.val().toFloat()*0.01;
			var $incaesurefeeafter = $tr.find(".incaesurefeeafter");
			var incaesurefeeafter = notdownfee + (incaesurefee-notdownfee) * (1-indiscount);
			$incaesurefeeafter.val(incaesurefeeafter.toMoney());
			
			var histroycaesurefeeafter = $tr.find(".histroycaesurefeeafter").val().toFloat(),$klincaesurefeeafter = $tr.find(".klincaesurefeeafter"),
			klincaesurefeeafter = incaesurefeeafter + histroycaesurefeeafter;
			$klincaesurefeeafter.val(klincaesurefeeafter.toMoney());														
		}
	}
	//通过第三级计算第二级的当月对内确权金额和开累对内确权金额总计
	var incaesurefee2 = function(type,$tr,$childTr){
		var incaesurefeeafter = 0;
		var klincaesurefeeafter = 0;
		var $ = layui.$;
		$childTr.find(".incaesurefeeafter").each(function(index,obj){
			if(type=='incaesurefee' ||type=='notdownfee'){
				if($(obj).val()==undefined||$(obj).val()==''||isNaN($(obj).val())){
					var thisincaesurefeeafter = 0;
					incaesurefeeafter = parseFloat(incaesurefeeafter) + parseFloat(thisincaesurefeeafter);	
				}else{
					incaesurefeeafter = parseFloat(incaesurefeeafter) + parseFloat($(obj).val());	
				}														
			}
		})
		$childTr.find(".klincaesurefeeafter").each(function(index,obj){
			if(type=='incaesurefee' ||type=='notdownfee'){
				if($(obj).val()==undefined||$(obj).val()==''||isNaN($(obj).val())){
					var thisklincaesurefeeafter = 0;
					klincaesurefeeafter = parseFloat(klincaesurefeeafter) + parseFloat(thisklincaesurefeeafter);	
				}else{
					klincaesurefeeafter = parseFloat(klincaesurefeeafter) + parseFloat($(obj).val());	
				}																		
			}
		})
		$tr.find(".incaesurefeeafter").val(incaesurefeeafter.toFixed(2));
		$tr.find(".klincaesurefeeafter").val(klincaesurefeeafter.toFixed(2));
	}
	//通过第二级计算第一级的当月对内确权金额和开累对内确权金额总计
	var incaesurefee3 = function(type,$tr,$parentTr){
		var incaesurefeeafter = 0;
		var klincaesurefeeafter = 0;
		var $ = layui.$;
		$parentTr.find(".incaesurefeeafter").each(function(index,obj){
			if(type=='incaesurefee' ||type=='notdownfee'){
				if($(obj).val()==undefined||$(obj).val()==''||isNaN($(obj).val())){
					var thisincaesurefeeafter = 0;
					incaesurefeeafter = parseFloat(incaesurefeeafter) + parseFloat(thisincaesurefeeafter);	
				}else{
					incaesurefeeafter = parseFloat(incaesurefeeafter) + parseFloat($(obj).val());	
				}											
			}
		})
		$parentTr.find(".klincaesurefeeafter").each(function(index,obj){
			if(type=='incaesurefee' ||type=='notdownfee'){
				if($(obj).val()==undefined||$(obj).val()==''||isNaN($(obj).val())){
					var thisklincaesurefeeafter = 0;
					klincaesurefeeafter = parseFloat(klincaesurefeeafter) + parseFloat(thisklincaesurefeeafter);	
				}else{
					klincaesurefeeafter = parseFloat(klincaesurefeeafter) + parseFloat($(obj).val());	
				}												
			}
		})
		$tr.find(".incaesurefeeafter").val(incaesurefeeafter.toFixed(2));
		$tr.find(".klincaesurefeeafter").val(klincaesurefeeafter.toFixed(2));
	}
	var incaeSureAdd = function($){
		var $contractList = $('.contract-list');				
		$contractList.on('keyup','.decimal', function() {
			var val = this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');
			var val2 = val.replace(/[^0-9.]/g, "");
			this.value = val2;
		}).on('blur','.layui-row .contract-money input[type=text]:not([readonly].decimal)', function() {
			if($(this).val() == ''){
				return;
			}
			var $tr = $(this).parents('tr');
			var type, id;
			type = $(this).prop('class')
					.replace('layui-input', '')
					.replace('decimal', '')
					.trim();					
			id = $tr.prop("id");
			
			if(!$(this).hasClass("typeNames") && !$(this).hasClass("indiscount")){
				arabiaToCN(this,1);
			}
			
			incaesurefee(type,$tr);		
			parentGroup($, type, id);
		});
	}
	
	
	var listModeDataBind = function($,data){		
		var $table = $('#list-mode').find('tbody');		
		var template = $('#list-mode-tr').html();
		$table.empty();		
		$table.on('keyup','.decimal', function() {
			var val = this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');
			var val2 = val.replace(/[^0-9.]/g,"");
			this.value = val2;
		}).on('keyup','.integer', function() {
			var val = this.value.replace(/^(\-)*([1-9]\d*)\.(\d\d).*$/,'$2');
			var val2 = val.replace(/[^0-9.]/g,"");
			this.value = val2;
		}).on('blur','input[type=text]', function() {
			var type = $(this).prop('class').replace('decimal','').replace('layui-input','').trim();
			var $tr = $(this).parents('tr');
			if(['contractprice','declarednum','incaesurenum'].indexOf(type)!=-1){
				sumPrice($tr);
			}
			var $total = $('#'+type);
			var total = $table.find("input[type=text]."+type).inputTotal();
			$total.val(total);
			if(type=='declarednum'){
				countTopRows($,['declaredamount']);
			}else if(type=='incaesurenum'){
				countTopRows($,['samemonthincaesureamount','kaileiincaesureamount']);
			}
		});
		
		for(var i=0,j=data.length;i<j;i++){
			var html=[],rowId=i+1;
			var item = data[i];
			var rowHtml = template.format(rowId,item.name,item.unit,item.contractprice,item.contractamount,item.historyprice);
			var $rowHtml = $(rowHtml);
			sumPrice($rowHtml);
			$table.append($rowHtml);
		}

		function sumPrice($tr){			
			var $contractprice = $tr.find('.contractprice'),contractprice = $contractprice.val().toFloat(),
			$declarednum = $tr.find('.declarednum'),declarednum = $declarednum.val().toFloat(),
			$incaesurenum = $tr.find('.incaesurenum'),incaesurenum = $incaesurenum.val().toFloat(),
			$declaredamount = $tr.find('.declaredamount'),
			$samemonthincaesureamount = $tr.find('.samemonthincaesureamount'),
			$kaileiincaesureamount = $tr.find('.kaileiincaesureamount'),
			$hisotryprice = $tr.find('.hisotryprice');
			
			var declaredamount = contractprice * declarednum;			
			$declaredamount.val(declaredamount.toMoney());
			
			var samemonthincaesureamount = contractprice * incaesurenum;
			$samemonthincaesureamount.val(samemonthincaesureamount.toMoney());
			
			var kaileiincaesureamount = samemonthincaesureamount + $hisotryprice.val().toFloat();
			$kaileiincaesureamount.val(kaileiincaesureamount.toMoney());			
		}
		
		function countTopRows($, types) {
			types.forEach(function(e) {
				var $total = $('#' + e);
				var total = $table.find("input[type=text]." + e).inputTotal();
				$total.val(total);
				if(e=='samemonthincaesureamount'){
					$('#id_monthAfterAmount').val(total);
				}
				if(e=='kaileiincaesureamount'){
					$('#id_addupAfterAmount').val(total);
				}
			});
		}
	}

	var uploadRender = function(id, upload, $) {
		upload.render({
					elem : '#' + id + '-upload-more',
					url : basePath + '/incaeSure/uploadAtt/',
					data : {
						types : id
					},
					multiple : true,
					accept : 'file',
					acceptMime : 'application/zip,application/x-rar-compressed,image/jpeg,image/png,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/pdf',
					before : function(obj) {
						layer.load();
					},
					done : function(res) {
						if (res.code > 0) {
							layer.closeAll('loading');
							return layer.msg(res.msg, {
								icon : 7
							});
						}
						if (res.entity != null && res.entity.length > 0) {
							for ( var i in res.entity) {
								var preProject = res.entity[i];
								var arr = preProject.split("|");
								var imgSrc = "";
								var suffix = arr[1].substring(arr[1]
										.lastIndexOf(".") + 1, arr[1].length);
								if (suffix == 'jpg' || suffix == 'png') {
									imgSrc = "${fileHttpPre}/" + arr[3];
								} else {
									imgSrc = "${ctx}/resources/images/"
											+ suffix + ".jpg";
								}
								$('#' + id + '-upload-more-list')
										.append(
												'<div class="layui-upload-img-div" id="upload_img_'+arr[2]+'"><img src="'+imgSrc+'" title="'+ arr[1] +'" class="layui-upload-img"><div class="mask"><a href="javascript:void(0)" onclick="showImg(\''
														+ "${fileHttpPre}"
														+ arr[3]
														+ '\');">查看</a><a href="javascript:void(0)" onclick="del(\''
														+ arr[2]
														+ '\')";>删除</a></div><p>'
														+ arr[1]
														+ '</p><input type="hidden" value="'+preProject+'" id="fileAtt_'+arr[2]+'" name="fileAtts'+id+'" ></input></div>');
							}
						}
					},
					allDone : function(obj) {
						layer.closeAll('loading');
					},
					error : function() {
						layer.closeAll('loading');
						layer.msg("上传失败，请稍后再试~", {
							icon : 7
						});
					}
				});
	}
	//删除文件
	function del(index) {
		layui.$("#fileAtt_" + index).remove();
		layui.$("#upload_img_" + index).remove();
	}

	//根据url查看文件
	function showImg(url) {
		var openWin = window.open(url,'','left=410,height=768, width=1024, top=200,  toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
	}
	
	function getIncaeSureByTypes(types) {
		var $ = layui.$, form = layui.form
		$.ajax({
			type : "POST", //提交方式  
			url : "${ctx}/incaeSure/getIncaeSureByTypes",//路径  
			data : {
				"types" : types
			},//数据，这里使用的是Json格式进行传输  
			success : function(result) {//返回数据根据结果进行相应的处理 
				if (result.flag == true) {
					var contractList = '<option value="">请选择</option>';
					if(types=='1'){//内部协议
						if(result.InnerAgrtList!=null){
							layui.$.each(result.InnerAgrtList, function(i,item){														
								contractList+=  '<option value='+item.proCode+'_'+item.id+'_'+item.proName+'_'+item.innerAgrtName+'>'+item.proName+'_'+item.innerAgrtName+'</option>';							
					        });
						}
						$('#add_select_proId').append(contractList);
					}else if(types=='2'){//分包合同
						if(result.selectSubpackCotList!=null){
							layui.$.each(result.selectSubpackCotList, function(i,item){														
								contractList+=  '<option value='+item.proCode+'_'+item.id+'_'+item.proName+'_'+item.subpackCotName+'>'+item.proName+'_'+item.subpackCotName+'</option>';							
					        });
						}
						$('#add_select_proId').append(contractList);
					}
					form.render();
				}
			}
		});
		
	}
	
	//根据合同名称带出需要的字段
	function getIncaeSureByProCode(id) {
		var $ = layui.$, form = layui.form
		var types = $('#add_select_cotType').val();
		$.ajax({
			type : "POST", //提交方式  
			url : "${ctx}/incaeSure/getIncaeSureByProCode",//路径  
			data : {
				"proCodeAndCodes" : id,
				"types" : types
			},//数据，这里使用的是Json格式进行传输  
			success : function(result) {//返回数据根据结果进行相应的处理 
				var layuiRowHtml = $('#layui-row').html(),$contractList = $('.contract-list');$contractList.find(".layui-row").remove();
				
				if (result.flag == true) {
					if(types=='1'){//合同类型为内部协议
						if(result.InnerAgrt!=null){
							$("#id_contractUnitName").attr("value",result.InnerAgrt.sgCoopName);//合同单位名称
							$("#sgCoopId").attr("value",result.InnerAgrt.sgCoopId);//合同单位id	
							$("#id_proName").attr("value", result.InnerAgrt.proName);//项目名称	
							$("#id_proCode").attr("value", result.InnerAgrt.proCode);//项目编号
							if(result.InnerAgrt.hrOrgAreaId!=null){
								$("#areaId").attr("value",result.InnerAgrt.hrOrgAreaId);//区域公司id
							}else{
								$("#areaId").attr("value",'');//区域公司id
							}			
							if (result.InnerAgrt.orgAreaName != null) {
								$("#id_regionalCompany").attr("value",result.InnerAgrt.orgAreaName);//区域公司
							} else {
								$("#id_regionalCompany").attr("value", "暂时为空不可编辑");//区域公司
							}
							if (result.InnerAgrt.hrOrgProId != null) {
								$("#compId").attr("value",result.InnerAgrt.hrOrgProId);//项目公司id
							}else{
								$("#compId").attr("value",'');//项目公司id
							}
							
							if (result.InnerAgrt.orgProName != null) {
								$("#id_projectCompany").attr("value",result.InnerAgrt.orgProName);//项目公司
							} else {
								$("#id_projectCompany").attr("value", "暂时为空不可编辑");//项目公司
			
							}
							$("#id_ImplementingBody").attr("value",result.InnerAgrt.carryOrg);//实施机构
							$("#sgCityId").attr("value",result.InnerAgrt.sgCityId);//项目城市id
							$("#id_projectAddress").attr("value",result.InnerAgrt.sgCityName);//项目地址
							$("#id_projectLeader").attr("value",result.InnerAgrt.proLeader);//项目负责人								
							$("#cotNameId").attr("value",result.InnerAgrt.innerAgrtName);//合同名称
							
							$("#indiscount").attr("value",result.InnerAgrt.innerDownRate);//对内下浮率(合计)
						}
						
						//内部协议名称带出确权模式（整体下浮）
						$("#id_sureType").attr("value",'1');//内部协议确权模式为整体下浮，设置为1
						$("#rightconfirmationmode").attr("value",'下浮模式');//内部协议确权模式为整体下浮，设置为整体下浮
						
						var hash = {},subList=[];					
						for(var i = 0, j = result.innerAgrtDetailAndSubList.length; i < j; i++) {												
							var e = result.innerAgrtDetailAndSubList[i];						
							if(typeof(hash[e.agrtSubId])=='undefined'){
								hash[e.agrtSubId] = subList.length;							
								subList.push({
									subName:e.subName,
									agrtSubId:e.agrtSubId,
									list:[{
										subRowId : e.orderIdx.indexOf(',')!=-1?e.orderIdx.split(',')[1]:e.orderIdx,
										costType : e.typeName.indexOf(',')!=-1?e.typeName.split(',')[1]:e.typeName,
										incontractfee : e.afterDownFee,
										indiscount : e.innerDownRate,
										histroycaesurefeeafter : e.addupAmountTotal
									}]
								});							

							}else{								
								var index =  hash[e.agrtSubId].toString().toInt();
								subList[index].list.push({
									subRowId : e.orderIdx.indexOf(',')!=-1?e.orderIdx.split(',')[1]:e.orderIdx,
									costType : e.typeName.indexOf(',')!=-1?e.typeName.split(',')[1]:e.typeName,
									incontractfee : e.afterDownFee,
									indiscount : e.innerDownRate,
									histroycaesurefeeafter : e.addupAmountTotal
								});						
							}						
						}
						
						for (var i = 0, j = subList.length; i < j; i++) {
							var e = result.innerAgrtDetailAndSubList[i];
							var itemNameSub = subList[i].subName,subId = subList[i].agrtSubId;
							var tempHtml = layuiRowHtml.format(subId,itemNameSub);
							var $html = $(tempHtml);
							subList[i].list.forEach(function(e) {
										var subRowId = e.subRowId;
										var costType = e.costType;					
										var incontractfee = e.incontractfee;
										var indiscount = e.indiscount;
										var histroycaesurefeeafter = e.histroycaesurefeeafter;
										
										var $row = $html.find('tr[id$="' + subId + 'Row-' + subRowId + '"]');
										if ($row.length == 1) {
											$row.find('input[type="hidden"]:eq(0)').val(subRowId);
											var $typeNames = $row.find('td:eq(1) input.typeNames');									
											if ($typeNames.val() != costType) {						
												$typeNames.val(costType);								
												var $lastPrev = $typeNames.prevAll(':last');
												$lastPrev.text(costType);
											}							
											$row.find('td:eq(2) input').val(incontractfee);
											$row.find('td:eq(6) input').val(indiscount);
											$row.find('td:eq(8) input[type=hidden]').val(histroycaesurefeeafter);
										} else {
											var arr = subRowId.split('.');
											var level = arr.length;
											if (level >= 2) {									
												var id = "sub"+subId+"Row-"+subRowId;												
												var types = subRowId.split('.');        
										        var feeTypes = types[0],feeSmallTypes = types[0]+'.'+types[1];								        												
												var $trHtml = $($('#layui-row-tr').html().format(id,level,subRowId,subId,costType,feeTypes,feeSmallTypes,itemNameSub,incontractfee,indiscount,histroycaesurefeeafter));
												
												var pop = arr.pop();
												var parent = arr.length==1? subId + 'Row-' + arr[0]:"sub" + subId + "Row-" + arr.join('.');								
												var siblings = (parent.indexOf('sub')==-1?'sub':'') + parent + '.';								
												var $parent = $html.find("tr[id='" + parent + "']");
												var $siblings = $html.find("tr[id^='" + siblings + "']");								
												var siblingslen = $siblings.length;							
												setReadonly($parent);
																				
												if (siblingslen > 0) {
													var $last = $($siblings[siblingslen - 1]);
													var lastId = $last.prop('id');
													if (lastId.split('.').pop() == pop - 1|| arr.length==1) {																				
														$last.after($trHtml);											 
													}
												} else if ($parent.length == 1 && pop == '1') {
													$parent.after($trHtml);
												}							
											}
										}
							});
							$contractList.append($html);
						}
						
						$('.contract-price-info:first').css('display','block');
						$('.contract-price-info:last').css('display','none');
					}else if(types=='2'){//合同类型为分包合同
						if(result.subpackCotDomain!=null){
							$("#id_contractUnitName").attr("value",result.subpackCotDomain.sgCoopName);//合同单位名称
							$("#sgCoopId").attr("value",result.subpackCotDomain.sgCoopId);//合同单位id	
							$("#id_proName").attr("value", result.subpackCotDomain.proName);//项目名称	
							$("#id_proCode").attr("value", result.subpackCotDomain.proCode);//项目编号
							if(result.subpackCotDomain.hrOrgAreaId!=null){
								$("#areaId").attr("value",result.subpackCotDomain.hrOrgAreaId);//区域公司id
							}else{
								$("#areaId").attr("value",'');//区域公司id
							}							
							if (result.subpackCotDomain.orgAreaName != null) {
								$("#id_regionalCompany").attr("value",result.subpackCotDomain.orgAreaName);//区域公司
							} else {
								$("#id_regionalCompany").attr("value", "暂时为空不可编辑");//区域公司
							}
							if(result.subpackCotDomain.hrOrgProId!=null){
								$("#compId").attr("value",result.subpackCotDomain.hrOrgProId);//项目公司id
							}else{
								$("#compId").attr("value",'');//项目公司id
							}							
							if (result.subpackCotDomain.orgProName != null) {
								$("#id_projectCompany").attr("value",result.subpackCotDomain.orgProName);//项目公司
							} else {
								$("#id_projectCompany").attr("value", "暂时为空不可编辑");//项目公司
			
							}
							$("#id_ImplementingBody").attr("value",result.subpackCotDomain.carryOrg);//实施机构
							$("#sgCityId").attr("value",result.subpackCotDomain.sgCityId);//项目城市id
							$("#id_projectAddress").attr("value",result.subpackCotDomain.sgCityName);//项目地址
							$("#id_projectLeader").attr("value",result.subpackCotDomain.proLeader);//项目负责人								
							$("#cotNameId").attr("value",result.subpackCotDomain.subpackCotName);//合同名称
				
							$("#indiscount").attr("value",result.subpackCotDomain.innerDownRate);//对内下浮率(合计)
						}
						
						//分包合同名称带出确权模式
						$("#id_sureType").attr("value",result.subpackCotDomain.cotType);//分包合同确权模式
						if(result.subpackCotDomain.cotType=='1'){
							$("#rightconfirmationmode").attr("value",'下浮模式');//分包合同确权模式为整体下浮
							//带出整体下浮明细
							var hash = {},subList=[];					
							for(var i = 0, j = result.subpackCotDetailAndSubList.length; i < j; i++) {												
								var e = result.subpackCotDetailAndSubList[i];						
								if(typeof(hash[e.cotSubId])=='undefined'){
									hash[e.cotSubId] = subList.length;							
									subList.push({
										subName:e.subName,
										cotSubId:e.cotSubId,
										list:[{
											subRowId : e.orderIdx.indexOf(',')!=-1?e.orderIdx.split(',')[1]:e.orderIdx,
											costType : e.typeName.indexOf(',')!=-1?e.typeName.split(',')[1]:e.typeName,
											incontractfee : e.afterDownFee,
											indiscount : e.innerDownRate,
											histroycaesurefeeafter : e.addupAmountTotal	
										}]
									});							

								}else{								
									var index =  hash[e.cotSubId].toString().toInt();
									subList[index].list.push({
										subRowId : e.orderIdx.indexOf(',')!=-1?e.orderIdx.split(',')[1]:e.orderIdx,
										costType : e.typeName.indexOf(',')!=-1?e.typeName.split(',')[1]:e.typeName,
										incontractfee : e.afterDownFee,
										indiscount : e.innerDownRate,
										histroycaesurefeeafter : e.addupAmountTotal
									});						
								}						
							}
							
							for (var i = 0, j = subList.length; i < j; i++) {
								var e = result.subpackCotDetailAndSubList[i];
								var itemNameSub = subList[i].subName,subId = subList[i].cotSubId;
								var tempHtml = layuiRowHtml.format(subId,itemNameSub);
								var $html = $(tempHtml);
								subList[i].list.forEach(function(e) {
											var subRowId = e.subRowId;
											var costType = e.costType;					
											var incontractfee = e.incontractfee;
											var indiscount = e.indiscount;
											var histroycaesurefeeafter = e.histroycaesurefeeafter;
											
											var $row = $html.find('tr[id$="' + subId + 'Row-' + subRowId + '"]');
											if ($row.length == 1) {
												$row.find('input[type="hidden"]:eq(0)').val(subRowId);
												var $typeNames = $row.find('td:eq(1) input.typeNames');									
												if ($typeNames.val() != costType) {						
													$typeNames.val(costType);								
													var $lastPrev = $typeNames.prevAll(':last');
													$lastPrev.text(costType);
												}							
												$row.find('td:eq(2) input').val(incontractfee);
												$row.find('td:eq(6) input').val(indiscount);
												$row.find('td:eq(8) input[type=hidden]').val(histroycaesurefeeafter);
											} else {
												var arr = subRowId.split('.');
												var level = arr.length;
												if (level >= 2) {									
													var id = "sub"+subId+"Row-"+subRowId;												
													var types = subRowId.split('.');        
											        var feeTypes = types[0],feeSmallTypes = types[0]+'.'+types[1];								        												
													var $trHtml = $($('#layui-row-tr').html().format(id,level,subRowId,subId,costType,feeTypes,feeSmallTypes,itemNameSub,incontractfee,indiscount,histroycaesurefeeafter));
													
													var pop = arr.pop();
													var parent = arr.length==1? subId + 'Row-' + arr[0]:"sub" + subId + "Row-" + arr.join('.');								
													var siblings = (parent.indexOf('sub')==-1?'sub':'') + parent + '.';								
													var $parent = $html.find("tr[id='" + parent + "']");
													var $siblings = $html.find("tr[id^='" + siblings + "']");								
													var siblingslen = $siblings.length;							
													setReadonly($parent);
																					
													if (siblingslen > 0) {
														var $last = $($siblings[siblingslen - 1]);
														var lastId = $last.prop('id');
														if (lastId.split('.').pop() == pop - 1|| arr.length==1) {																				
															$last.after($trHtml);											 
														}
													} else if ($parent.length == 1 && pop == '1') {
														$parent.after($trHtml);
													}							
												}
											}
								});
								$contractList.append($html);
							}
							$('.contract-price-info:first').css('display','block');
							$('.contract-price-info:last').css('display','none');	
							
						}else if(result.subpackCotDomain.cotType=='2'){
							$("#rightconfirmationmode").attr("value",'清单模式');//分包合同确权模式为清单模式
							$("#contractamount").attr("value",result.subpackCotDomain.totalSumWhen);//合同总额	
							//带出清单模式明细
							var listModeData = [];	
							for(var i = 0;i < result.subpackCotLists.length; i++) {												
								var e = result.subpackCotLists[i];						
								listModeData.push({
									name:e.subName,
									unit:e.subUnit,
									contractprice:e.cotUnitPrice,
									contractamount:e.cotSumPrice,
									historyprice:e.addupAmountTotal
								});							
							}
							listModeDataBind($,listModeData);
							$('.contract-price-info:first').css('display','none');
							$('.contract-price-info:last').css('display','block');
						}
					}
					var type = $('#rightconfirmationmode').val(),$contractPriceInfo = $('.contract-price-info');						
					if(type=='清单模式'){
						$('.contract-price-info:first').css('display','none');
						$('.contract-price-info:last').css('display','block');						
						$('#incaesurefeeafter').removeAttr('name')
						$('#klincaesurefeeafter').removeAttr('name')
						$("#samemonthincaesureamount").attr("name","monthAfterAmount");
						$("#kaileiincaesureamount").attr("name","addupAfterAmount");
						listModeDataBind($,listModeData);
					}						
					if(type=='下浮模式'){
						$('.contract-price-info:first').css('display','block');
						$('.contract-price-info:last').css('display','none');
						$('#samemonthincaesureamount').removeAttr('name')
						$('#kaileiincaesureamount').removeAttr('name')
						$("#incaesurefeeafter").attr("name","monthAfterAmount");
						$("#klincaesurefeeafter").attr("name","addupAfterAmount");
						incaeSureAdd($);
					}					
					countTopRows($, ['incontractfee']);	
					form.render();
				}
			}
		});
	}

	//'请输入正确数字，且保留两位小数！'
	function isNumberAndFloat2(str) {
		var rgx = /^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/;
		var boolrgx = rgx.test(str);// true 
		if (boolrgx) {
			return true;
		} else {
			return false;
		}
	}

</script>